package com.esri.core.map;

import com.esri.core.internal.util.d;
import com.esri.core.io.EsriServiceException;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class Field implements Serializable {
    private static final String a = "esriFieldTypeInteger";
    private static final String b = "esriFieldTypeSmallInteger";
    private static final String c = "esriFieldTypeDouble";
    private static final String d = "esriFieldTypeSingle";
    private static final String e = "esriFieldTypeString";
    public static final int esriFieldTypeBlob = 90;
    public static final int esriFieldTypeDate = 50;
    public static final int esriFieldTypeDouble = 30;
    public static final int esriFieldTypeGUID = 110;
    public static final int esriFieldTypeGeometry = 70;
    public static final int esriFieldTypeGlobalID = 100;
    public static final int esriFieldTypeInteger = 10;
    public static final int esriFieldTypeOID = 80;
    public static final int esriFieldTypeRaster = 120;
    public static final int esriFieldTypeSingle = 40;
    public static final int esriFieldTypeSmallInteger = 20;
    public static final int esriFieldTypeString = 60;
    public static final int esriFieldTypeXML = 130;
    private static final String f = "esriFieldTypeDate";
    private static final String g = "esriFieldTypeGeometry";
    private static final String h = "esriFieldTypeOID";
    private static final String i = "esriFieldTypeBlob";
    private static final String j = "esriFieldTypeGlobalID";
    private static final String k = "esriFieldTypeGUID";
    private static final String l = "esriFieldTypeRaster";
    private static final String m = "esriFieldTypeXML";
    private static final long serialVersionUID = 1;
    private String n;
    private String o;
    private String p;
    private int q;
    private boolean r;
    private boolean s;
    private int t;
    private Domain u;

    public static String toEsriFieldType(int i2) {
        if (10 == i2) {
            return a;
        }
        if (20 == i2) {
            return b;
        }
        if (30 == i2) {
            return c;
        }
        if (40 == i2) {
            return d;
        }
        if (60 == i2) {
            return e;
        }
        if (50 == i2) {
            return f;
        }
        if (70 == i2) {
            return g;
        }
        if (80 == i2) {
            return h;
        }
        if (90 == i2) {
            return i;
        }
        if (100 == i2) {
            return j;
        }
        if (110 == i2) {
            return k;
        }
        if (120 == i2) {
            return l;
        }
        if (130 == i2) {
            return m;
        }
        return null;
    }

    public Field() {
        this.s = true;
        this.u = null;
    }

    public Field(String str, String str2, String str3) throws Exception {
        this(str, str2, str3, null);
    }

    public Field(String str, String str2, String str3, Domain domain) throws Exception {
        this.s = true;
        this.u = null;
        this.n = str;
        if (str.equals("")) {
            throw new EsriServiceException("Field Name Empty Exception");
        }
        this.o = str2;
        this.p = str3;
        int fieldType = toFieldType(str3);
        this.q = fieldType;
        if (fieldType < 0) {
            throw new EsriServiceException("Invalid field type: " + str3);
        }
        this.u = domain;
    }

    public String getName() {
        return this.n;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Field [");
        if (this.n != null) {
            sb.append("name=");
            sb.append(this.n);
            sb.append(", ");
        }
        if (this.o != null) {
            sb.append("alias=");
            sb.append(this.o);
            sb.append(", ");
        }
        if (this.p != null) {
            sb.append("type=");
            sb.append(this.p);
            sb.append(", ");
        }
        sb.append("type_int=");
        sb.append(this.q);
        sb.append(", editable=");
        sb.append(this.r);
        sb.append(", length=");
        sb.append(this.t);
        sb.append(", ");
        if (this.u != null) {
            sb.append("domain=");
            sb.append(this.u);
        }
        sb.append("]");
        return sb.toString();
    }

    public String getAlias() {
        return this.o;
    }

    public int getFieldType() {
        return this.q;
    }

    public boolean isEditable() {
        return this.r;
    }

    public boolean isNullable() {
        return this.s;
    }

    public int getLength() {
        return this.t;
    }

    void a(int i2) {
        this.t = i2;
    }

    public Domain getDomain() {
        return this.u;
    }

    public static List<Field> fromJson(String str) throws Exception {
        JsonParser c2 = d.c(str);
        ArrayList arrayList = new ArrayList();
        try {
            c2.nextToken();
            if (c2.getCurrentToken() == JsonToken.START_ARRAY) {
                arrayList = new ArrayList();
                while (c2.nextToken() != JsonToken.END_ARRAY) {
                    arrayList.add(fromJson(c2));
                }
            }
            return arrayList;
        } finally {
            c2.close();
        }
    }

    public static Field fromJson(JsonParser jsonParser) throws Exception {
        if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
            return null;
        }
        Field field = new Field();
        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
            String currentName = jsonParser.getCurrentName();
            jsonParser.nextToken();
            if ("name".equals(currentName)) {
                field.n = a(jsonParser.getText());
            } else if ("type".equals(currentName)) {
                String text = jsonParser.getText();
                field.p = text;
                field.q = toFieldType(text);
            } else if ("alias".equals(currentName)) {
                field.o = jsonParser.getText();
            } else if ("editable".equals(currentName)) {
                field.r = jsonParser.getBooleanValue();
            } else if ("nullable".equals(currentName)) {
                field.s = jsonParser.getBooleanValue();
            } else if ("length".equals(currentName)) {
                field.t = jsonParser.getIntValue();
            } else if ("domain".equals(currentName)) {
                field.u = Domain.fromJson(jsonParser);
            }
        }
        return field;
    }

    private static String a(String str) {
        int lastIndexOf = str.lastIndexOf(46);
        return lastIndexOf == -1 ? str : str.substring(lastIndexOf + 1);
    }

    public static String toJson(Field field) throws Exception {
        StringWriter stringWriter = new StringWriter();
        JsonGenerator a2 = d.a(stringWriter);
        a2.writeStartObject();
        a2.writeStringField("name", field.n);
        a2.writeStringField("alias", field.o);
        a2.writeStringField("type", field.p);
        boolean z = field.r;
        if (z) {
            a2.writeBooleanField("editable", z);
        }
        int i2 = field.t;
        if (i2 > 0) {
            a2.writeNumberField("length", i2);
        }
        if (field.u != null) {
            a2.writeFieldName("domain");
            a2.writeRawValue(Domain.toJson(field.u));
        }
        a2.writeEndObject();
        a2.close();
        return stringWriter.toString();
    }

    public static int toFieldType(String str) {
        if (a.equals(str)) {
            return 10;
        }
        if (b.equals(str)) {
            return 20;
        }
        if (c.equals(str)) {
            return 30;
        }
        if (d.equals(str)) {
            return 40;
        }
        if (e.equals(str)) {
            return 60;
        }
        if (f.equals(str)) {
            return 50;
        }
        if (g.equals(str)) {
            return 70;
        }
        if (h.equals(str)) {
            return 80;
        }
        if (i.equals(str)) {
            return 90;
        }
        if (j.equals(str)) {
            return 100;
        }
        if (k.equals(str)) {
            return 110;
        }
        if (l.equals(str)) {
            return 120;
        }
        return m.equals(str) ? 130 : -1;
    }
}
